package com.example.administrator.exkotlin.jetpack.lifecycle

import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent

/**
 * Author by lp,on 2020/8/28/028,17:14.
 * 没有Lifecycle的时候一般情况使用自定义的监听器实现此类功能
 * LifecycleObserver 让没有在activity中的方法和类，简单化的观察Activity的什么生命周期
 */
class MyObserver(val lifecycle: Lifecycle) :LifecycleObserver {
    val TAG="MyObserver"
    fun getNowLifeState(): Lifecycle.State = lifecycle.currentState

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    fun createState(){
        Log.i(TAG,"已经完成OnCreate生命周期")
    }
    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    fun startState(){
        Log.i(TAG,"已经完成ON_START生命周期")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    fun resumeState(){
        Log.i(TAG,"已经完成ON_RESUME生命周期")
    }
    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    fun pauseState(){
        Log.i(TAG,"已经完成ON_PAUSE生命周期")
    }
    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    fun stopState(){
        Log.i(TAG,"已经完成O=ON_STOP生命周期")
    }
    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    fun destoryState(){
        Log.i(TAG,"已经完成ON_DESTROY生命周期")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_ANY)
    fun anyState(){
        Log.i(TAG,"已经完成ON_ANY生命周期")
    }


}